/**
 * 
 */
package data;

import java.util.HashMap;
import java.util.Vector;

/**
 * @author yexijiang
 * @date 2008-7-2
 */
public class SimilaritySet 
{
	//private String m_SetName;
	private int m_Dimension;
	private String m_TargetTag;
	private Vector<String> m_Keys;
	private HashMap<String, Vector<Double>> m_Records;
	
	/*public SimilaritySet(String name, String target)
	{
		//m_SetName = name;
		m_TargetTag = target;
		m_Records = new HashMap<String, Vector<Double>>();
		m_Keys = new Vector<String>();
	}*/
	
	public SimilaritySet(String target, int dimension)
	{
		m_Dimension = dimension;
		m_TargetTag = target;
		m_Records = new HashMap<String, Vector<Double>>();
		m_Keys = new Vector<String>();
	}
	
	public void addRecord(String recName, Vector<Double> rec)
	{
		m_Keys.add(recName);
		m_Records.put(recName, rec);
	}
	
	public void removeRecord(String recName)
	{
		//m_Keys.remove(recName);
		m_Records.remove(recName);
	}
	
	public void removeKeyByIndex(int index)
	{
		String key = m_Keys.get(index);
		m_Keys.remove(index);
		m_Records.remove(key);
	}
	
	
	/*public String getName()
	{
		return m_SetName;
	}*/
	
	public String getTargetTag()
	{
		return m_TargetTag;
	}
	
	public Vector<Double> getRecordByKeys(String recName)
	{
		return m_Records.get(recName);
	}
	
	public void updateVector(String recName, Vector<Double> newVector)
	{
		m_Records.remove(recName);
		m_Records.put(recName, newVector);
	}
	
	public void addValueByRecName(String recName, int dimIndex, Double value)
	{
		if(m_Records.containsKey(recName) == true)
		{
			Vector<Double> v = m_Records.get(recName);
			v.set(dimIndex, value);
			m_Records.remove(recName);
			m_Records.put(recName, v);
		}
		else
		{
			m_Keys.add(recName);
			Vector<Double> values = new Vector<Double>(m_Dimension);
			values.setSize(m_Dimension);
			values.set(dimIndex, value);
			m_Records.put(recName, values);
		}
	}
	
	public Vector<Double> getRecordByIndex(int index)
	{
		return m_Records.get(m_Keys.get(index));
	}
	
	public Vector<String> getKeys()
	{
		return m_Keys;
	}
	
	public int getIndexByLabel(String label)
	{
		for(int i = 0; i < m_Keys.size(); ++i)
		{
			if(label.equals(m_Keys.get(i)))
				return i;
		}
		return -1;
		
	}
	
	public int size()
	{
		return m_Records.size();
	}
	
	public String toString()
	{
		String msg = new String();
		msg += m_TargetTag + "\n";
		
		for(int i = 0; i < m_Records.size(); ++i)
		{
			msg += m_Keys.get(i) + ":" + m_Records.get(m_Keys.get(i)) + "\n";
		}
		
		return msg;
	}
	
}
